package com.aiyun.securiy.login.security;

import javax.cache.Cache;
import javax.cache.CacheManager;

import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;

/**
 * 自定义令牌存储，如果是JWT则不需要该类
 */
@Component
public class UserList {

	private final CacheManager cacheManager;

	public UserList(CacheManager cacheManager) {
		this.cacheManager = cacheManager;
	}


	public void setToken(String token, Authentication authentication){
		getCache().put(token, authentication);
	}

	public Authentication getAuthentication(String token){
		if (token == null) return null;
		return getCache().get(token);
	}

	public Cache<String, Authentication> getCache(){
		return cacheManager.getCache("userInfo");
	}
}
